var rankName = {
	'1':'签约',
	'2':'应诊',
	'3':'预约',
	'4':'好评',
	'5':'投诉'
}

var dataUrlInfo = {
	'provinceWeek':'/hdds/statistics/province/signList/lastweek/'+userInfos.provinceId,//排行榜（省）》上一周
	'provinceMonth':'/hdds/statistics/province/signList/lastmonth/'+userInfos.provinceId,//排行榜（省）》上一月
	'provinceSeason':'/hdds/statistics/province/signList/lastseason/'+userInfos.provinceId,//排行榜（省）》上一季
	'cityWeek':'/hdds/statistics/city/signList/lastweek/'+userInfos.cityId,//排行榜（市）》上一周
	'cityMonth':'/hdds/statistics/city/signList/lastmonth/'+userInfos.cityId,//排行榜（市）》上一月
	'citySeason':'/hdds/statistics/city/signList/lastseason/'+userInfos.cityId,//排行榜（市）》上一季
	'areaWeek':'/hdds/statistics/area/signList/lastweek/'+userInfos.areaId,//排行榜（县）》上一周
	'areaMonth':'/hdds/statistics/area/signList/lastmonth/'+userInfos.areaId,//排行榜（县）》上一月
	'areaSeason':'/hdds/statistics/area/signList/lastseason/'+userInfos.areaId//排行榜（县）》上一季
	
}
function myajax(dataUrl,successfn){
	hui.ajax({
	    type : 'GET',
	    url : globleobj['domain']+dataUrl,
	    data :'',
	    beforeSend : function(){hui.loading();},
	    complete   : function(){hui.closeLoading();},
	    success : function(msg){
	    	console.log('getsignuser:'+msg)
	    	var data = JSON.parse(msg)
	    	if(data.rc != 0){
	    		hui.toast(data.msg);  
	    		return false; 
	    	}
	    	console.log(JSON.stringify(data.body) == '{}')
	    	
	    	successfn(data);
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
	}); 
}


function getsignuser(dataUrl){
		var pravceNum1 = {}
		var pravceArray = {}; //和
		var options = '';
		
		myajax(dataUrl,function(res){
			
			hui(".performance").remove();

			for(var arr in res.body){ 
	    		var pravce1 = 0;
	    		var pravce2 = 0;
	    		var pravce4 = 0;
	    		var pravce5 = 0;
				var pravceArr = [];
				
//	    		console.log(arr)
	    		for(var i= 0; i < res.body[arr].length; i++){   
					pravce1 +=res.body[arr][i].signNum;
					pravce2 +=res.body[arr][i].consultationNum;
					pravce4 +=res.body[arr][i].praiseNum;
					pravce5 +=res.body[arr][i].complaintNum;
					
	    		}
	    		
	    		pravceArr.push({
					type:'签约数',
					strNum:pravce1,
					img:'../../img/qianyuetu.png'
				})
	    		pravceArr.push({
					type:'应诊数',
					strNum:pravce2,
					img:'../../img/yinzhenLogo.png'
				})
	    		pravceArr.push({
					type:'好评数',
					strNum:pravce4,
					img:'../../img/haopinLogo.png'
				})
	    		pravceArr.push({
					type:'投诉数',
					strNum:pravce5,
					img:'../../img/tousuLogo.png'
				})
	    		
	    		if(!pravceNum1[arr]){
	    			pravceNum1[arr] = pravceArr;
	    		}
	    		if(!pravceArray[arr]){
	    			pravceArray[arr] = (pravce1*0.01)+(pravce2*0.05)+(pravce4*0.3)-(pravce5);
	    		}
	    	}
//			console.log(JSON.stringify(pravceNum1))
//			console.log(JSON.stringify(pravceArray))
			
			for(var arrname in pravceNum1){ 
				
				options += '<div class="performance">'+
				    '<div class="performanceTitle">'+
				    	'<span>'+arrname+'</span>'+
				    	'<span>'+pravceArray[arrname]+'分</span>'+
				    '</div>'+
				    '<div class="performanceContent">'+
				    	'<ul class="clearfix">';
				    	for(var j = 0 ; j < pravceNum1[arrname].length; j++){
				    		options +='<li>'+
				    			'<div>'+
				    				'<img src="'+pravceNum1[arrname][j].img+'"/>'+
				    			'</div>'+
				    			'<div class="performanceinfo">'+
				    				'<div class="clearfix">'+
				    					'<div>'+
				    						'<div class="hui-progress" >'+
										        '<!--<span></span>-->'+
										        '<div class="hui-progressing progressall"></div>'+
										    '</div>'+
				    					'</div>'+
									    '<p class="infoNumber">'+pravceNum1[arrname][j].strNum+'</p>'+
				    				'</div>'+
				    				'<p>'+pravceNum1[arrname][j].type+'</p>'+
				    			'</div>'+
				    		'</li>';
				    	}
				    	options +='</ul>'+
				    '</div>'+
				'</div>';
			}
			hui(".hui-wrap").html(options);
		})
	
}

//签约
function sign(dataInfo){
	hui.ajax({
	    type : 'POST',
	    url : globleobj['domain']+'/residents/sign',
	    data : dataInfo,
	    beforeSend : function(){hui.loading();},
	    complete   : function(){hui.closeLoading();},
	    success : function(msg){
	    	console.log('sign'+msg)
	    	var data = JSON.parse(msg);
	    	if(data.rc != 0){
	    		hui.toast(data.msg); 
	    		return false; 
	    	}
	    	
			hui.iconToast('签约完成！');
	        setTimeout(function(){
	        	hui.open('myDoctor.html',{},true);
	        },1000)
	    	
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
	}); 
}



hui.ready(function(){
	if(userInfos.userLevel == 1 ){
		getsignuser(dataUrlInfo.provinceWeek);
	}else if(userInfos.userLevel == 2 ){
		getsignuser(dataUrlInfo.cityWeek);
	}else if(userInfos.userLevel == 3 ){
		getsignuser(dataUrlInfo.areaWeek);
	}
	hui('#hui-back').click(function(){
//	    hui.toast('返回');
	});
	


    hui.plusReady(function(){
    	console.log('plusReady')
    });
});